package com.sanchunhui.psc.data.dao

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
import com.j256.ormlite.support.ConnectionSource
import com.j256.ormlite.table.TableUtils
import com.sanchunhui.psc.data.protocol.UserInfo


/**
 * @Author zyx
 * @Date 2021/4/27-10:39
 * @Dscribe
 */

/**
 * app版本  数据库版本
 */
class PSCOpenHelper(val context: Context) : OrmLiteSqliteOpenHelper(context,"psc_kotlin.db",null,1) {
    override fun onCreate(p0: SQLiteDatabase?, p1: ConnectionSource?) {
        //创建user表
        TableUtils.createTable(connectionSource, UserInfo::class.java)
    }

    override fun onUpgrade(p0: SQLiteDatabase?, p1: ConnectionSource?, p2: Int, p3: Int) {
        //升级app的用户会执行此方法
        TableUtils.dropTable<UserInfo, Any>(connectionSource, UserInfo::class.java, true)
        TableUtils.createTable(connectionSource, UserInfo::class.java)
    }

}